package com.ruoyi.bigbase.api.factory;

import com.ruoyi.bigbase.api.RemoteCustomerService;
import com.ruoyi.bigbase.api.domain.Customer;
import com.ruoyi.bigbase.api.domain.IntegralDetails;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

@Component
public class RemoteCustomerFactory implements FallbackFactory<RemoteCustomerService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteCustomerFactory.class);

    @Override
    public RemoteCustomerService create(Throwable cause) {
        System.out.print("调用失败！");
        return new RemoteCustomerService() {
            @Override
            public TableDataInfo list(Customer customer, String source) {
                return new TableDataInfo(new ArrayList<>(), 0L);
            }

            @Override
            public R<Customer> getCustomerInfo(Integer id, String source) {
                return R.fail("获取用户信息失败");
            }

            @Override
            public AjaxResult addPoints(IntegralDetails integralDetails, String source) {
                return AjaxResult.error();
            }

            @Override
            public Integer getTimeByUserId(Integer userId, String source) {
                return null;
            }
        };
    }
}
